<% layout('/layout/default.html', {title: '菜单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
		<div class="card-header">
				<i class="fa icon-book-open"></i> 菜单管理
			<div class="header-tools float-right">
			
				<a href="#" class="btn btn-sm btn-secondary" id="btnRefreshTree" title="刷新"><i class="fa fa-refresh"></i> 刷新</a>
				<a href="#" class="btn btn-sm btn-secondary" id="btnExpandTreeNode" title="展开一级"><i class="fa fa-angle-double-down"></i> 展开</a>
				<a href="#" class="btn btn-sm btn-secondary" id="btnCollapseTreeNode" title="折叠全部"><i class="fa fa-angle-double-up"></i> 折叠</a>
				<% if(hasPermi('sys:menu:edit')){ %>
					<a href="/sys/menu/form" class="btn btn-sm btn-secondary btnTool"  title="新增菜单"><i class="fa fa-plus"></i> 新增</a>
					
					<a href="#" class="btn btn-sm btn-secondary" id="btnUpdateSort" title="保存排序"><i class="fa fa-sort-amount-asc"></i> 保存排序</a>
				<% } %>
			</div>
		</div>
		<div class="container-fluid">
			<form id="searchForm" action="${ctx}/sys/menu/listData" method="post" class="form-inline d-none" >
				<div class="form-group">
					<button type="submit" class="btn btn-primary ">查询</button>
					<button type="reset" class="btn btn-sm btn-secondary ">重置</button>
				</div>
			</form>

			<form id="dataGridForm" action="${ctx}/sys/menu/updateSort" method="post" >
				<table id="btGrid"></table>
			</form>
		</div>
</div>
<% } %>
<script>
//初始化DataGrid对象
$('#btGrid').BTGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{title:'菜单名称', field:'name', width:200, formatter: function(val, row, index){
			return '<i class="'+row.icon+'"></i> <a href="/sys/menu/form?id='
					+row.id+'" class="btnList" data-title="编辑菜单">'+val+'</a>';
		}},
		{title:'链接', field:'href', width:150},
		{title:'排序', field:'sort', width:63, align:"center", formatter: function(val, row, index){
			var html = [];
			<% if(hasPermi('sys:menu:edit')){ %>
			html.push('<input type="hidden" name="ids" value="'+row.id+'"/>');
			html.push('<input name="sorts" type="text" value="'+row.sort+'" style="width:50px;height:19px;margin:0;padding:0;text-align:center;border:1px solid #ddd">');
			<% }else{ %>
			html.push(row.sort);
			<% } %>
			return html.join('');
		}},
		{title:'可见', field:'isShow', width:50, align:"center", formatter: function(val, row, index){
			return val=="1"?"显示":"隐藏";
		}},
		{title:'权限标识', field:'permission', width:150},
		{title:'操作', field:'actions', width:100, sortable:false, align:"center", formatter: function(val, row, index){
			var actions = [];
			<% if(hasPermi('sys:menu:edit')){ %>
                actions.push('<a href="/sys/menu/form?parentId='+row.id+'" class="btn btn-sm btn-success btnList" title="新增下级菜单"><i class="fa fa-plus-square"></i></a>&nbsp;&nbsp;');
				actions.push('<a href="/sys/menu/form?id='+row.id+'" class="btn btn-sm btn-primary btnList" title="编辑菜单"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;');
				actions.push('<a href="${ctx}/sys/menu/delete?id='+row.id+'" class="btn btn-sm btn-danger btnList" title="删除菜单" data-confirm="确认要删除该菜单及所有子菜单吗？" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>');

			<% } %>
			return actions.join('');
		}}
	],
    idField: 'id',
    treeShowField: 'name',
    parentIdField: 'pid',
    treeEnable: true,
    rootParentId: '0',
    treeIcons : {
        plus: "ui-icon-circlesmall-plus",
        minus: "ui-icon-circlesmall-minus",
        leaf : "ui-icon-document"
    },
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});



//绑定更新排序按钮
$('#btnUpdateSort').click(function(){
	 js.ajaxSubmitForm($("#dataGridForm"), function(data){
		if(data.result == "true"){
			$('#btnRefreshTree').click();
		}
		js.showMessage(data.message);
	});
});
</script>